package Stack;
import java.util.*;
public class MyStack {
    private final Queue<Integer> queue1;        //入队
    private final Queue<Integer> queue2;
    public MyStack() {
        queue1=new LinkedList<>();
        queue2=new LinkedList<>();
    }

    public void push(int x) {
        queue1.offer(x);
    }

    public int pop() {
        while(queue1.size()>1) {
            int x=queue1.poll();
            queue2.offer(x);
        }
        int val=queue1.poll();
        while(queue2.size()>0) {
            int x=queue2.poll();
            queue1.offer(x);
        }
        return val;
    }

    public int top() {
        int x=0;
        while(queue1.size()>0) {
            x=queue1.poll();
            queue2.offer(x);
        }
        while(queue2.size()>0) {
            int y=queue2.poll();
            queue1.offer(y);
        }
        return x;
    }

    public boolean empty() {
        return queue1.size()==0&&queue2.size()==0;
    }
}
